package com.asset.dispoal.defaultCompanyRole.service.commom;

import com.asset.dispoal.defaultCompanyRole.domain.db.entity.GbDefaultCompanyRole;
import com.asset.dispoal.defaultCompanyRole.domain.db.mapper.GbDefaultCompanyRoleMapper;
import com.asset.dispoal.defaultCompanyRole.dto.GbDefaultCompanyRoleRequest;
import com.asset.dispoal.defaultCompanyRole.service.converter.GbDefaultCompanyRoleConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.core.id.BaseIdeable;
import tech.mhuang.pacebox.springboot.protocol.Result;

/**
 * @author qr
 * @date 2022/3/17$
 */
@Component
public class GbDefaultCompanyRoleInsert implements BaseCommand<GbDefaultCompanyRoleRequest, Result> {

    @Autowired
    GbDefaultCompanyRoleMapper gbDefaultCompanyRoleMapper;

    @Autowired
    private BaseIdeable<String> ideable;

    @Override
    public Result execute(GbDefaultCompanyRoleRequest request) {
        GbDefaultCompanyRole gbDefaultCompanyRole = GbDefaultCompanyRoleConverter.INSTANCE.reqToDo(request);
        gbDefaultCompanyRole.setId(ideable.generateId());
        gbDefaultCompanyRoleMapper.insert(gbDefaultCompanyRole);
        return Result.ok();
    }
}
